package com.inkyi.assistant.app.tools.comps;

import com.inkyi.assistant.app.base.InkComponent;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;


public class EnvironmentVarTable extends JPanel implements InkComponent {

    private final String[] columnNames = {"Key", "Value"};
    private DefaultTableModel tableModel;
    private JTable table;
    private JScrollPane scrollPane;


    public EnvironmentVarTable() {
        initComponents();
    }

    @Override
    public void initComponents() {
        this.setLayout(new CardLayout());
        // 初始化表格模型，允许编辑
        tableModel = new DefaultTableModel(columnNames, 0) {
            // 允许单元格编辑
            @Override
            public boolean isCellEditable(int row, int column) {
                return false; // 可以根据需要设置为 false 以禁止编辑
            }
        };
        table = new JTable(tableModel);
        scrollPane = new JScrollPane(table);
        this.add(scrollPane);
    }

    public void addRow(Object[] rawData) {
        tableModel.addRow(rawData);
    }

    public void clearRow() {
        tableModel.getDataVector().clear();
    }


    public static void main(String[] args) {
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(800, 600);
        EnvironmentVarTable panel = new EnvironmentVarTable();
        frame.setContentPane(panel);
        frame.setVisible(true);
    }


}
